//
//  ViewController.m
//  界面动画集
//
//  Created by YYY on 2017/6/27.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "ViewController.h"

#import "AnimationGroupController.h"
//#import "UIViewController+WXSTransition.h"

#import "NextViewController.h"

//设置表视图和导航栏不分离

@interface ViewController () <UITableViewDelegate,UITableViewDataSource>
{
    UIView *tempView;
    
    //UIImageView *tempImageView;
    
    UIView *headerView;
}
@property(nonatomic,strong)UITableView *myTableView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
    
    self.title = @"动画集";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Animation" style:UIBarButtonItemStylePlain target:self action:@selector(animationGroup)];
    
    [self.view addSubview:self.myTableView];
}

-(void)animationGroup
{
    AnimationGroupController *group = [[AnimationGroupController alloc]init];
    [self.navigationController pushViewController:group animated:YES];
}

-(UITableView *)myTableView
{
    if (!_myTableView)
    {
        _myTableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.contentInset = UIEdgeInsetsMake(100, 0, 0, 0);
        
        tempView = [[UIView alloc]initWithFrame:CGRectMake(0, -100, self.view.frame.size.width, 100)];
        
//        UIColor *color = [UIColor cyanColor];
//        CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
//        
//        UIGraphicsBeginImageContext(rect.size);
//        
//        CGContextRef context = UIGraphicsGetCurrentContext();
//        
//        CGContextSetFillColorWithColor(context, [color CGColor]);
//        
//        CGContextFillRect(context, rect);
//        
//        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//        
//        UIGraphicsEndImageContext();
        tempView.backgroundColor = [UIColor cyanColor];
        [_myTableView addSubview:tempView];

        headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 100)];
        [tempView addSubview:headerView];
        
    }
    return _myTableView;
}

#pragma mark UITableView delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 25;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NextViewController *nextVC = [[NextViewController alloc]init];
    if (indexPath.row==24 || indexPath.row==23)
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        nextVC.flag = 1;
        [self.navigationController wxs_pushViewController:nextVC makeTransition:^(WXSTransitionProperty *transition) {
            transition.animationType = WXSTransitionAnimationTypePointSpreadPresent;
            transition.animationTime = 1;
            //transition.backGestureEnable = NO;
            transition.startView = cell.contentView;
        }];
    }
    else
    {
        nextVC.flag = 0;
        [self wxs_presentViewController:nextVC animationType:WXSTransitionAnimationTypePageTransition + indexPath.row completion:nil];
    }
}

#pragma mark UIScrollView delegate 设置表视图和导航栏不分离
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat y = scrollView.contentOffset.y + 64;
    if (y < -100)
    {
        CGRect rect = tempView.frame;
        rect.origin.y = y;
        rect.size.height = -y;
        tempView.frame = rect;
        headerView.frame = CGRectMake(0, -y-100, self.view.frame.size.width, 100);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
